import math
#
# The following formulas are adapted from the Aviation Formulary
# http://williams.best.vwh.net/avform.htm
#

nauticalMilePerLat = 60.00721
nauticalMilePerLongitude = 60.10793
rad = math.pi / 180.0
milesPerNauticalMile = 1.15078
kmsPerMile = 1.609344
kmsPerNauticalMile = milesPerNauticalMile * kmsPerMile

def calcDistance(geoPt1, geoPt2):
    """
    Caclulate distance (in Kms) between two lat lons in NM
    """
    yDistance = (geoPt2.lat - geoPt1.lat) * nauticalMilePerLat
    xDistance = (math.cos(geoPt1.lat * rad) + math.cos(geoPt2.lat * rad)) * (geoPt2.lon - geoPt1.lon) * (nauticalMilePerLongitude / 2)
    distance = math.sqrt( yDistance**2 + xDistance**2 )
    
    return distance * kmsPerNauticalMile # milesPerNauticalMile
